import { hex_md5 } from './md5.js'
import { DES3 } from './DES3.js'
// import cookie from 'jquery.cookie'
// 隐藏数字中间, 调用：numHide(13888888888)或numHide('13888888888')
export const numHide = function (m) {
  if (m.length <= 11) {
    return m.substr(0, 3) + '****' + m.substr(7)
  } else {
    return m.substr(0, 4) + ' **** **** ' + m.substr(13)
  }
}

// 字符串转日期格式，strDate要转为日期格式的字符串
export const getDate = function (strDate) {
  // strDate为需要转换成日期格式的字符串
  if (strDate.replace('/')) {
    strDate = strDate.replace('/', '-').replace('/', '-')
  }
  var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
      function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')')
  return date
}


// 获取url中的参数   传入参数名name
export const getUrlParam = function (name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); // 构造一个含有目标参数的正则表达式对象
  var r = window.location.search.substr(1).match(reg); // 匹配目标参数
  if (r != null) return unescape(r[2]); return null; // 返回参数值
}

export function uuid (len, radix) {
  var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
  var uuid = [], i
  radix = radix || chars.length

  if (len) {
    // Compact form
    for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]
  } else {
    // rfc4122, version 4 form
    var r

    // rfc4122 requires these characters
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
    uuid[14] = '4'

    // Fill in random data.  At i==19 set the high bits of clock sequence as
    // per rfc4122, sec. 4.1.5
    for (i = 0; i < 36; i++) {
      if (!uuid[i]) {
        r = 0 | Math.random() * 16
        uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]
      }
    }
  }

  return uuid.join('')
}
